package com.hainatong.jcmvvmbase.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.widget.TextView;
import com.hainatong.jcmvvmbase.R;

public class LoadingDialog extends Dialog
{


    public LoadingDialog(Context context)
    {
        super(context);
    }

    public LoadingDialog(Context context, String msg)
    {
        this(context, R.style.CustomProgressDialog, msg);
    }

    public LoadingDialog(Context context, int theme, String msg)
    {
        super(context, theme);
        this.setContentView(R.layout.loading_dialog);
        // 设置点击外部无效
        this.setCanceledOnTouchOutside(false);
        // 设置点击返回键可以dismiss
        this.setCancelable(true);
        // 设置居中显示
        this.getWindow().getAttributes().gravity = Gravity.CENTER;
        // 初始化文本框
        TextView tvMsg = (TextView)this.findViewById(R.id.id_tv_loadingmsg);
        // 设置文本框内提示信息
        tvMsg.setText(msg);
    }

    public LoadingDialog setMessage(String msg)
    {
        TextView tvMsg = (TextView)this.findViewById(R.id.id_tv_loadingmsg);
        tvMsg.setText(msg);
        return this;
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus)
    {
        if (!hasFocus)
        {
            dismiss();
        }
    }
}
